package com.vue.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vue.mapper.UserMapper;
import com.vue.pojo.User;
import com.vue.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserImpl extends ServiceImpl<UserMapper,User> implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public Page<User> findAll(Integer pagenumber, Integer pagesize) {
        Page<User> page=new Page<>(pagenumber,pagesize);
        return userMapper.selectPage(page,new QueryWrapper<User>().gt("role",1));
    }

    @Override
    public int delOne(Integer id) {
        return userMapper.deleteById(id);
    }

    @Override
    public int upOne(User user) {
        return userMapper.updateById(user);
    }

    @Override
    public int insOne(User user) {
        return userMapper.insert(user);
    }

    @Override
    public int upPas(String id, String pad) {
        User user=new User();
        user.setId(Integer.parseInt(id));
        user.setPwd(pad);
        return userMapper.updateById(user);
    }

    @Override
    public User finOne(String username,Integer role) {
        return userMapper.selectOne(new QueryWrapper<User>().eq("userName",username).eq("role",role));
    }

    @Override
    public User findOnee(Integer id) {
        return userMapper.selectById(id);
    }
}
